/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:lenovo
 * Date:2024-05-09
 * Time:17:20
 */
import java.util.Arrays;

/*
public class ArrayTest {
    */
/*public static void bubbleSort(int[] array){
        //i表示循环的趟数
        for (int i = 0; i < array.length-1; i++) {
            boolean flag=false;
            for (int j = 0; j < array.length-1-i; j++) {
                //从小到大排序
                if(array[j]>array[j+1]) {
                    int tempArray = array[j];
                    array[j]=array[j+1];
                    array[j+1]=tempArray;
                    flag=true;
                }
            }
            if(flag==false)
                return;
        }
    }*//*

    public static void main(String[] args) {

    }
}
*/


import java.util.Arrays;
import java.util.Scanner;

public class ArrayTest {
   /* public static void main(String[] args) {
        int count = 0;
        //定义一个计量数，计算中奖了几次
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要抽取数字的最高数：");
        int n = sc.nextInt();
        //设定一个n存放最高位数值
        int n1 = n;
        //定义了一个n1与n的数值相同
        System.out.println("请输入您要抽取几个数字(1~"+n+"):");
        int k = sc.nextInt();
        //设定了抽取数
        if(k>n){
            System.out.println("对不起，您输入的数字不符合规范！");
            //若此时抽取数比最高数要高则报错
        }else{
            int[] numbers1 = new int[n];
            int[] numbers2 = new int[n1];
            //定义了两个数组，其长度分别与n和n1相同
            for (int i = 0; i < numbers1.length; i++) {
                numbers1[i] = i+1;
                //对数组numbers进行从1~n的赋值;
            }
            for (int i = 0; i < numbers2.length; i++) {
                numbers2[i] = i+1;
                //对数组numbers2进行从1~n1的赋值;
            }
            int[] result = new int[k];//抽取结果
            //定义了result数组使其长度等于抽取数k
            for (int i = 0; i < result.length; i++) {
                int r =(int) (Math.random()*n);
                //Math.random()*n会得到一个0到n-1之间的随机数，左闭右开！
                //抽取随机数的本质是抽取随机下标
                result[i] = numbers1[r];
                //选择随机数numbers[r]赋值给result[i]
                numbers1[r] = numbers1[n - 1];
                n--;
                //这里确保了不会再次抽取到同一个值
            }
            int[] winning = new int[k];//中奖结果
            for (int i = 0; i < winning.length; i++) {
                int w = (int) (Math.random()*n);
                winning[i] = numbers2[w];
                numbers2[w] = numbers2[n1 - 1];
                n1--;
            }
            Arrays.sort(result);
            //对数组进行排序
            System.out.println("抽取完成，您抽取的数为：");
            for(int r :result){
                System.out.print(r+" ");
            }
            //使用foreach循环对数组进行遍历
            System.out.println("");
            //换行
            Arrays.sort(winning);
            System.out.println("中奖数为：");
            for (int w:winning){
                System.out.print(w+" ");
            }
            for (int x = 0; x < result.length; x++) {
                for (int y = 0; y < winning.length; y++) {
                    if(result[x] == winning[y]){
                        count++;
                    }
                }
            }
            //使用两个for循环且利用if语句对数组的值进行判断
            //若有相同值则count计数值自增
            System.out.println();
            if(count == 0){
                System.out.println("对不起，您未中奖，请再接再厉！");
            }else{
                System.out.println("恭喜您，您中奖了"+count+"次");
            }
        }

    }*/
   public static void main1(String[] args) {
        int[][] list={{1,2,3},{4,5,6},{7,8,9}};
        //法一：
       for (int i = 0; i < list.length; i++) {
           for (int j = 0; j < list[0].length; j++) {
               System.out.print(list[i][j]+" ");
           }
           System.out.println();
       }
       System.out.println("==================");
       //法二：
       for (int[] x :list) {
           for (int y:x) {
               System.out.print(y+" ");
           }
           System.out.println();
       }
   }

    public static void main2(String[] args) {
        int[][] a = new int[10][];

        for (int i = 0; i < a.length; i++) {
            // 给二维数组中每一个一维数组在堆上开辟内存空间
            a[i] = new int[i + 1];
            // 遍历每一个一维数组，赋值
            for (int j = 0; j < a[i].length; j++) {
                // 每一行的第一个元素和最后一个元素都是1
                if (j == 0 || j == a[i].length - 1) {
                    a[i][j] = 1;
                } else {
                    // 每一行非第一个元素和最后一个元素的值 = 上一行的同一列 + 上一行的上一列
                    a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
                }
            }
        }

        // 输出杨辉三角
        for (int i = 0; i < a.length; i++) {
            for (int k = 0; k < a[i].length; k++) {
                System.out.print(a[i][k] + "\t");
            }
            System.out.println();
        }
    };

    public static void main(String[] args) {
            int[] array = new int[10];
            Arrays.fill(array,5);
            Arrays.fill(array,4,6,10);
            System.out.println(Arrays.toString(array));
        }
}

